import { useEffect, useRef, useState } from "react"

export const usedown=(num=60)=>{
    // 点击“获取验证码”按钮文字进行60s倒计时
    const [count,setcount]=useState(num)
    const [isdown,setisdown]=useState(false)
    const timeref=useRef(null)
    function start(){
        setisdown(true)
        timeref.current=setInterval(()=>{
            setcount((perv)=>perv-1)
        },1000)
    }
    useEffect(()=>{
        if(count<=0){
            clearInterval(timeref.current)
            setisdown(false)
            setcount(true)
        }
    },[count,num])
    return {count,isdown,start}
}
